<template>
  <view class="container">
		<nav-ber :title="'激活流程'" :bgColor="'#f7f8ff'"></nav-ber>
		<view class="province">
			<u-steps  :current="current" direction="column">
				<u-steps-item title="第一步: 公司信息审核">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="(status == 2 && status != 3)? '已完成': (status == 1? '已提交' : (status == 3? '已驳回' : '未完成'))" :type="(status >= 2 && status != 3)? 'success' : 'warning'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="flex:1">
								需提交公司营业执照、法人身份证正反面、开户许可证审核。
							</view>
							<view style="margin-left: 20rpx;">
								<u-button  v-if="status==3 || status==0" @click="companyInformationFun" type="primary" text="去完成"></u-button>
								<u-button v-else @click="companyInformationFun('1')" type="primary" text="查看"></u-button>
							</view>
						</view>
					</view>
				</u-steps-item>
				<u-steps-item title="第二步: 签订协议">
					<view slot="desc">
						<view style="margin: 20rpx 0;display: inline-block;overflow: hidden;">
							<u-tag size="mini" style="display: inline-block;" :text="status == 4?'已完成': (status == 5? '已提交':(status == 6?'已驳回':'未完成'))" :type="status != 4? 'warning' : 'success'" plain plainFill></u-tag>
						</view>
						<view class="dis_flex">
							<view style="">
								<view style="display: flex;align-items: center;">
									医药代表需完成服务协议在线签订。
									<view>
										<u-button :disabled="!(status == 6 || status == 2)" @click="addagencyAgreementFun" type="primary" :text="(status == 6 || status == 2 || status == 0 || status == 1)? '提交':'已提交'"></u-button>
									</view>
								</view>
								<view :style="(status == 6 || status == 2)? '':'pointer-events:none'">
									<uFrom ref="getFrom" :itemList="itemList" :itemKeys.sync="itemKeys" @changeFun="changeFun"></uFrom>
								</view>
								<view :style="(status == 6 || status == 2)? '':'pointer-events:none'">
									<uFrom ref="getFrom" :itemList="itemList1" :itemKeys.sync="itemKeys1" @changeFun="changeFun1"></uFrom>
								</view>
								<view :style="(status == 6 || status == 2)? '':'pointer-events:none'">
									<uFrom ref="getFrom" :itemList="itemList2" :itemKeys.sync="itemKeys2" @changeFun="changeFun2"></uFrom>
								</view>
							</view>
							
						</view>
					</view>
				</u-steps-item>
			</u-steps>
		</view>
  </view>
</template>
<script>
	import { itemList, itemList1, itemList2 } from './items.js'
	import { getbyuser, medicalRepresentative } from "@/api/login/index.js"
	import { addagencyAgreement, agencyBuId  } from '@/api/personalCenter.js'
  export default {
    data() {
			return {
				agreementListNew: [],
				current: 0,
				keyword: '',
				ispro: '1',
				bottonisShow: true,
				itemList: itemList,
				itemList1: itemList1,
				itemList2: itemList2,
				itemKeys: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				itemKeys1: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				itemKeys2: {
					fileList: [],
					photoList: [],
					urlFil: '',
					documentList: []
				},
				status: null,
				Id: '',
			}
    },
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
				if(option.type == 1){
					this.bottonisShow = false
				}
//打印出上个页面传递的参数。传递的是id=1，则获取到的就是option.id
		},
		onShow() {
			
			((JSON.parse(uni.getStorageSync('userInfo')).userType == '02')? medicalRepresentative : getbyuser)(JSON.parse(uni.getStorageSync('userInfo')).userId).then((resmin) => {
				this.status = resmin.data.status
				this.Id = resmin.data.id
				this.agencyBuIdFun()
				this.currentFun()
			})
			// this.agencyBuIdFun()
		},
		methods: {
			currentFun() {
				if (this.status!=4) {
					this.current =1
				}
				if (this.status>2) {
					this.current = 0
				}
				
				if (this.status==4) {
					this.current =2
				}
			},
			agencyBuIdFun() {
				agencyBuId(this.Id).then((res) => {
					if (this.agreementListNew.length) return
					if (!res.data.agreementList.length) return
					this.agreementListNew = res.data.agreementList
					this.itemKeys.documentList = res.data.agreementList.filter(item => item.type == 0)
					this.itemKeys.urlFil = this.itemKeys.documentList[0]?.url
					this.itemKeys1.documentList = res.data.agreementList.filter(item => item.type == 1)
					this.itemKeys1.urlFil = this.itemKeys1.documentList[0]?.url
					this.itemKeys2.documentList = res.data.agreementList.filter(item => item.type == 2)
					this.itemKeys2.urlFil = this.itemKeys2.documentList[0]?.url
				})
			},
			addagencyAgreementFun() {
				console.log('1241', this.itemKeys)
				console.log(this.itemKeys1)
				console.log(this.itemKeys2)
				console.log('this.agreementListNew', this.agreementListNew)
				// return
				if (this.agreementListNew.length != 3) {
					uni.showToast({
					  title: '请上传协议后提交',
					  icon: "none",
					  duration: 2000,
					})
					return
				}
				addagencyAgreement({
					agreementList: this.agreementListNew,
					id: this.Id
				}).then((res) => {
					uni.showToast({
					  title: '上传成功',
					  icon: "none",
					  duration: 2000,
						success: () => {
							setTimeout(() => {
								((JSON.parse(uni.getStorageSync('userInfo')).userType == '02')? medicalRepresentative : getbyuser)(JSON.parse(uni.getStorageSync('userInfo')).userId).then((resmin) => {
									this.status = resmin.data.status
								})
								this.currentFun()
								this.agencyBuIdFun()
							}, 800)
							
						}
					})
				})
			},
			changeFun(val) {
				
				this.agreementListNew[val.fileType] = val.agreementList[0]
				this.agreementListNew[val.fileType].type = 0
				
				console.log('fsad24123', this.agreementListNew)
			},
			changeFun1(val) {
				this.agreementListNew[val.fileType] = val.agreementList[0]
				this.agreementListNew[val.fileType].type = 1
				console.log('fsad241236677', this.agreementListNew)
			},
			changeFun2(val) {
				this.agreementListNew[val.fileType] = val.agreementList[0]
				this.agreementListNew[val.fileType].type = 2
				console.log('fsad241236677y54586', this.agreementListNew)
			},
			companyInformationFun(type) {
				uni.navigateTo({
					url: `/pages/personalCenter/companyInformation/index?id=${this.Id}${type == '1'? '&check=1': ''}`
				})
			},
		}
  }
</script>
<style lang="scss" scoped>
	.container {
		background-color: #f7f8ff;
		display: flex;
		flex-direction: column;
		height: 100vh;
		overflow: hidden;
	}
	.province {
		flex: 1;
		overflow: scroll;
		padding: 0 20rpx;
		margin-top: 20rpx;
	}
	.dis_flex {
		display: flex;
		align-items: flex-start;
	}
</style>
